package com.vf.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.scheduling.annotation.EnableAsync;
import com.vf.cloud.dev.Dev;
import com.vf.cloud.server.mongodb.MongodbServer;
import com.vf.cloud.server.redis.RedisServer;

import java.io.File;
import java.util.UUID;

@EnableAsync
@SpringBootApplication
public class VfCloudPassApplication {

	public static void main(String[] args) {
		
		if(Dev.INTEGRATED_MODE) {
			RedisServer.getInstance().run();
			RedisServer.getInstance().isRunning();
			
			MongodbServer.getInstance().run();
			MongodbServer.getInstance().isRunning();
			getSoftPath(); //发布时启用
		}
		
		SpringApplication.run(VfCloudPassApplication.class, args);

	}

	public static void getSoftPath() {
		ApplicationHome ah = new ApplicationHome(VfCloudPassApplication.class);
		File file = ah.getSource();
		Dev.SOFT_PATH = file.getParentFile().getParent();
		Dev.SOFT_PATH = Dev.SOFT_PATH.replace("\\", "/");
	}

	public static int getOrderNo() {
		Integer uuid = UUID.randomUUID().toString().replaceAll("-", "").hashCode();
		uuid = uuid < 0 ? -uuid : uuid;// String.hashCode() 值会为空
		return uuid;
	}

}
